// %1585222074420:%
/*
 * Copyright [2018] [Alex/libo(liboms@hotmail.com)]
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hyts.template.common;

import org.yaml.snakeyaml.Yaml;

import java.io.IOException;

import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Paths;


/**
 * @title YamlFileTemplate.java
 * @package com.hyts.template.common
 * @author libo/Alex
 * @email liboms@hotmail.com/liboware@163.com
 * @date 2018年5月7日
 * @version V1.0
 */
public class BaseYamlFileTemplate {
    /**
     * yaml文件对象
     */
    private static Yaml yaml = new Yaml();

    /**
     * 输出文件
     * @param param
     * @param outputFilePath
     */
    public static void output(Object param, String outputFilePath) {
        try {
            if (Files.notExists(Paths.get(outputFilePath),
                        LinkOption.NOFOLLOW_LINKS)) {
                Files.createFile(Paths.get(outputFilePath));
            }

            yaml.dump(param,
                Files.newBufferedWriter(Paths.get(outputFilePath),
                    Charset.forName("UTF-8"), LinkOption.NOFOLLOW_LINKS));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
